package cn.sfrog.project.biz.admin.service.impl;

import cn.sfrog.common.utils.SecurityUtils;
import cn.sfrog.project.biz.admin.domain.BizStudyProjectMember;
import cn.sfrog.project.biz.admin.domain.vo.BizStudyProjectMemberFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizStudyProjectMemberQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizStudyProjectMemberVO;
import cn.sfrog.project.biz.admin.mapper.BizStudyProjectMemberMapper;
import cn.sfrog.project.biz.admin.service.IBizStudyProjectMemberService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * 学研项目成员Service业务层处理
 */
@Service
public class BizStudyProjectMemberServiceImpl extends ServiceImpl<BizStudyProjectMemberMapper, BizStudyProjectMember> implements IBizStudyProjectMemberService {
    @Resource
    private BizStudyProjectMemberMapper bizStudyProjectMemberMapper;

    /**
     * 查询学研项目成员
     *
     * @param id 学研项目成员主键
     * @return 学研项目成员
     */
    @Override
    public BizStudyProjectMemberVO selectBizStudyProjectMemberById(Long id) {
        return bizStudyProjectMemberMapper.selectBizStudyProjectMemberById(id);
    }

    /**
     * 查询学研项目成员列表
     *
     * @param query 学研项目成员
     * @return 学研项目成员
     */
    @Override
    public List<BizStudyProjectMemberVO> selectBizStudyProjectMemberList(BizStudyProjectMemberQueryVO query) {
        return bizStudyProjectMemberMapper.selectBizStudyProjectMemberList(query);
    }

    /**
     * 新增学研项目成员
     *
     * @param form 学研项目成员
     * @return 结果
     */
    @Transactional(rollbackFor = Throwable.class)
    @Override
    public boolean insertBizStudyProjectMember(BizStudyProjectMemberFormVO form) {
        BizStudyProjectMember bizStudyProjectMember = new BizStudyProjectMember();
        BeanUtils.copyProperties(form, bizStudyProjectMember);
        bizStudyProjectMember.setCreateTime(new Date());
        bizStudyProjectMember.setCreateBy(SecurityUtils.getUsername());
        bizStudyProjectMember.setUpdateTime(new Date());
        bizStudyProjectMember.setUpdateBy(SecurityUtils.getUsername());
        return bizStudyProjectMember.insert();
    }

    /**
     * 修改学研项目成员
     *
     * @param form 学研项目成员
     * @return 结果
     */
    @Transactional(rollbackFor = Throwable.class)
    @Override
    public boolean updateBizStudyProjectMember(BizStudyProjectMemberFormVO form) {
        BizStudyProjectMember bizStudyProjectMember = new BizStudyProjectMember();
        BeanUtils.copyProperties(form, bizStudyProjectMember);
        bizStudyProjectMember.setUpdateTime(new Date());
        bizStudyProjectMember.setUpdateBy(SecurityUtils.getUsername());
        return bizStudyProjectMember.updateById();
    }

    /**
     * 批量删除学研项目成员
     *
     * @param ids 需要删除的学研项目成员主键
     * @return 结果
     */
    @Transactional(rollbackFor = Throwable.class)
    @Override
    public boolean deleteBizStudyProjectMemberByIds(Long[] ids) {
            return BizStudyProjectMember.DAO.delete(Wrappers.lambdaQuery(BizStudyProjectMember.class).in(BizStudyProjectMember::getId, (Object[]) ids));
    }

    @Transactional(rollbackFor = Throwable.class)
    @Override
    public boolean changeStatus(BizStatusChangeVO vo) {
        return true;
    }
}
